package cn.zaichi.edu.excelcommon.plugs.convertor;

import cn.zaichi.edu.excelcommon.error.ConvertExceptionEnum;
import cn.zaichi.edu.excelcommon.exception.ConvertException;
import cn.zaichi.edu.excelcommon.plugs.ReadConvertor;
import cn.zaichi.edu.excelcommon.plugs.WritConvertor;

/**
 * 性别转换器 1 男，2女
 */
public class SexConvertor implements ReadConvertor,WritConvertor {

    private static final int sex_man=1;
    private static final int sex_women=2;
    @Override
    public Object readerConvert(Object value,String param) {
        if(value==null){
            return null;
        }
        if(value.equals("男")){
            return sex_man;
        }else if(value.equals("女")){
            return sex_women;
        }else{
            throw new ConvertException(ConvertExceptionEnum.CONVERT_ERROR);
        }
    }

    @Override
    public Object writConvert(Object value,String param) {
        if(value==null){
            return null;
        }
        if(value.equals(sex_man)){
            return "男";
        }else if(value.equals(sex_women)){
            return "女";
        }else{
            throw new ConvertException(ConvertExceptionEnum.CONVERT_ERROR);
        }
    }
}
